<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="真实姓名" prop="truename">
        <el-input
          v-model="queryParams.truename"
          placeholder="请输入真实姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


      <el-form-item label="是否自动接单" prop="isReceiveOrder">
        <el-input
          v-model="queryParams.isReceiveOrder"
          placeholder="输入数值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['hmk:manage:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['hmk:manage:edit']"
        >修改
        </el-button>
      </el-col>
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="danger"-->
      <!--          plain-->
      <!--          icon="el-icon-delete"-->
      <!--          size="mini"-->
      <!--          :disabled="multiple"-->
      <!--          @click="handleDelete"-->
      <!--          v-hasPermi="['hmk:manage:remove']"-->
      <!--        >删除</el-button>-->
      <!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['hmk:manage:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="manageList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="主键" align="center" prop="id"/>
      <el-table-column label="是否锁定，1：否；2：是" align="center" prop="locks"/>
      <el-table-column label="真实姓名" align="center" prop="truename"/>
      <!--      <el-table-column label="用户组id" align="center" prop="groupId" />-->
      <!--      <el-table-column label="电话" align="center" prop="tel" />-->
      <!--      <el-table-column label="结算价折扣" align="center" prop="discount" />-->
      <!--      <el-table-column label="号码复制条件" align="center" prop="noticemsg" />-->
      <!--      <el-table-column label="订单显示分销商户  1全部   2部分" align="center" prop="orderStoreType" />-->
      <!--      <el-table-column label="订单显示指定分销商户id" align="center" prop="orderStoreArr" />-->
      <!--      <el-table-column label="订单显示号码仓  1全部   2部分" align="center" prop="orderSupplierType" />-->
      <!--      <el-table-column label="订单显示指定号码仓id" align="center" prop="orderSupplierArr" />-->
      <!--      <el-table-column label="订单显示状态  1全部   2部分" align="center" prop="orderStatusType" />-->
      <!--      <el-table-column label="订单显示指定状态id" align="center" prop="orderStatusArr" />-->
      <!--      <el-table-column label="号码显示号码仓  1全部   2部分" align="center" prop="telSupplierType" />-->
      <!--      <el-table-column label="号码显示指定号码仓id" align="center" prop="telSupplierArr" />-->
      <!--      <el-table-column label="号码显示状态  1全部   2部分" align="center" prop="telStatusType" />-->
      <!--      <el-table-column label="号码显示指定状态id" align="center" prop="telStatusArr" />-->
      <!--      <el-table-column label="最近的一次操作时间" align="center" prop="lastTime" />-->
      <el-table-column label="是否在线 1否    2是" align="center" prop="isOnline"/>
      <el-table-column label="弹窗提醒条件   1需要在线   2无需在线" align="center" prop="remindType"/>
      <el-table-column label="是否参与主播竞赛排名1、是2、否" align="center" prop="isAnchorCompetition"/>
      <el-table-column label="是否参与客服竞赛排名1、是2、否" align="center" prop="isServiceCompetition"/>
      <el-table-column label="是否展示订单全部搜索条件1、是2、否" align="center" prop="isOrderOptions"/>
      <!--      <el-table-column label="发展人编码-ZOP下单使用" align="center" prop="zopReferrercode" />-->
      <el-table-column label="0不接单1接单" align="center" prop="isReceiveOrder"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['hmk:manage:edit']"
          >修改
          </el-button>
          <!--          <el-button-->
          <!--            size="mini"-->
          <!--            type="text"-->
          <!--            icon="el-icon-delete"-->
          <!--            @click="handleDelete(scope.row)"-->
          <!--            v-hasPermi="['hmk:manage:remove']"-->
          <!--          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改总后台管理员对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="是否锁定，1：否；2：是" prop="locks">
          <el-input v-model="form.locks" placeholder="请输入是否锁定，1：否；2：是"/>
        </el-form-item>
        <el-form-item label="真实姓名" prop="truename">
          <el-input v-model="form.truename" placeholder="请输入真实姓名"/>
        </el-form-item>
        <el-form-item label="创建时间" prop="time">
          <el-input v-model="form.time" placeholder="请输入创建时间"/>
        </el-form-item>
        <el-form-item label="用户组id" prop="groupId">
          <el-input v-model="form.groupId" placeholder="请输入用户组id"/>
        </el-form-item>
        <el-form-item label="电话" prop="tel">
          <el-input v-model="form.tel" placeholder="请输入电话"/>
        </el-form-item>
        <el-form-item label="头像" prop="img">
          <el-input v-model="form.img" placeholder="请输入头像"/>
        </el-form-item>
        <el-form-item label="省id" prop="shengId">
          <el-input v-model="form.shengId" placeholder="请输入省id"/>
        </el-form-item>
        <el-form-item label="市id" prop="cityId">
          <el-input v-model="form.cityId" placeholder="请输入市id"/>
        </el-form-item>
        <el-form-item label="区id" prop="areaId">
          <el-input v-model="form.areaId" placeholder="请输入区id"/>
        </el-form-item>
        <el-form-item label="详细地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入详细地址"/>
        </el-form-item>
        <el-form-item label="结算价折扣" prop="discount">
          <el-input v-model="form.discount" placeholder="请输入结算价折扣"/>
        </el-form-item>
        <el-form-item label="号码复制条件" prop="noticemsg">
          <el-input v-model="form.noticemsg" placeholder="请输入号码复制条件"/>
        </el-form-item>
        <el-form-item label="订单显示指定分销商户id" prop="orderStoreArr">
          <el-input v-model="form.orderStoreArr" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="订单显示指定号码仓id" prop="orderSupplierArr">
          <el-input v-model="form.orderSupplierArr" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="订单显示指定状态id" prop="orderStatusArr">
          <el-input v-model="form.orderStatusArr" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="号码显示指定号码仓id" prop="telSupplierArr">
          <el-input v-model="form.telSupplierArr" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="号码显示指定状态id" prop="telStatusArr">
          <el-input v-model="form.telStatusArr" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="最近的一次操作时间" prop="lastTime">
          <el-input v-model="form.lastTime" placeholder="请输入最近的一次操作时间"/>
        </el-form-item>
        <el-form-item label="是否在线 1否    2是" prop="isOnline">
          <el-input v-model="form.isOnline" placeholder="请输入是否在线 1否    2是"/>
        </el-form-item>
        <el-form-item label="是否参与主播竞赛排名
1、是
2、否" prop="isAnchorCompetition">
          <el-input v-model="form.isAnchorCompetition" placeholder="请输入是否参与主播竞赛排名
1、是
2、否"/>
        </el-form-item>
        <el-form-item label="是否参与客服竞赛排名
1、是
2、否" prop="isServiceCompetition">
          <el-input v-model="form.isServiceCompetition" placeholder="请输入是否参与客服竞赛排名
1、是
2、否"/>
        </el-form-item>
        <el-form-item label="是否展示订单全部搜索条件
1、是
2、否" prop="isOrderOptions">
          <el-input v-model="form.isOrderOptions" placeholder="请输入是否展示订单全部搜索条件
1、是
2、否"/>
        </el-form-item>
        <el-form-item label="发展人编码-ZOP下单使用" prop="zopReferrercode">
          <el-input v-model="form.zopReferrercode" placeholder="请输入发展人编码-ZOP下单使用"/>
        </el-form-item>
        <el-form-item label="0不接单1接单" prop="isReceiveOrder">
          <el-input v-model="form.isReceiveOrder" placeholder="请输入0不接单1接单"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {addManage, delManage, getManage, listManage, updateManage} from "@/api/hmk/manage";

export default {
  name: "Manage",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 总后台管理员表格数据
      manageList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        locks: null,
        truename: null,
        time: null,
        groupId: null,
        tel: null,
        img: null,
        shengId: null,
        cityId: null,
        areaId: null,
        address: null,
        discount: null,
        noticemsg: null,
        orderStoreType: null,
        orderStoreArr: null,
        orderSupplierType: null,
        orderSupplierArr: null,
        orderStatusType: null,
        orderStatusArr: null,
        telSupplierType: null,
        telSupplierArr: null,
        telStatusType: null,
        telStatusArr: null,
        lastTime: null,
        isOnline: null,
        remindType: null,
        isAnchorCompetition: null,
        isServiceCompetition: null,
        isOrderOptions: null,
        zopReferrercode: null,
        isReceiveOrder: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        truename: [
          {required: true, message: "真实姓名不能为空", trigger: "blur"}
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询总后台管理员列表 */
    getList() {
      this.loading = true;
      listManage(this.queryParams).then(response => {
        this.manageList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        locks: null,
        truename: null,
        time: null,
        groupId: null,
        tel: null,
        img: null,
        shengId: null,
        cityId: null,
        areaId: null,
        address: null,
        discount: null,
        noticemsg: null,
        orderStoreType: null,
        orderStoreArr: null,
        orderSupplierType: null,
        orderSupplierArr: null,
        orderStatusType: null,
        orderStatusArr: null,
        telSupplierType: null,
        telSupplierArr: null,
        telStatusType: null,
        telStatusArr: null,
        lastTime: null,
        isOnline: null,
        remindType: null,
        isAnchorCompetition: null,
        isServiceCompetition: null,
        isOrderOptions: null,
        zopReferrercode: null,
        isReceiveOrder: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加总后台管理员";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getManage(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改总后台管理员";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateManage(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addManage(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除总后台管理员编号为"' + ids + '"的数据项？').then(function () {
        return delManage(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('hmk/manage/export', {
        ...this.queryParams
      }, `manage_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
